﻿<?php 
class AccountController extends Zend_Controller_Action
{
	public function newAction()
	{
		$form = new Zend_Form();
		$form->setAction('success');
		$form->setMethod('post');
		$form->setDescription("sign up form");
		$form->setAttrib('sitename','loudbite');
		
		//Add element to form --> de phet day chu:D
		
		// tao truong username
		$form->addElement('text','username');
		$usernameElement = $form->getElement('username');
		$usernameElement->setLabel('Ten Dang Nhap:');
		
		// tao truong email
		$form->addElement('text','email');
		$emailElement = $form->getElement('email');
		$emailElement->setLabel('Email:');
		
		// Tao truong password
		$form->addElement('password','password');
		$passwordElement = $form->getElement('password');
		$passwordElement->setLabel('Mat Khau:');

		// Tao nut submit
		$form->addElement('submit','submit');
		$submitButton = $form->getElement('submit');
		$submitButton->setLabel('Tao tai khoan');
		
		// Add the form to the view
		$this->view->form = $form;
	}
	
	
	public function testConnAction()
	{	
	
		try{
		    $params = array(
						'host' =>'localhost',
						'username' =>'340608',
						'password' =>'20061973',
						'dbname' => '340608'
						);
			//$db = new Zend_Db_Adapter_Pdo_Mysql($params);


			$db = Zend_Db::factory('mysqli', $params);
			Zend_Db_Table_Abstract::setDefaultAdapter($db);
			Zend_Registry::set('db', $db);
	
			/*
			$data = array(
					'article_id' => '1',
					'category_id' => '1'
			);	
			
			$table = 'article_to_category';
			$db->insert($table, $data);

			//$select = new Zend_Db_Select($db);
			//$result = $select->from('category')->query();			
			//var_dump($result);
			
			*/
			$result = $db->fetchOne('SELECT name FROM category');
			//echo "------------>";
			echo $result;
		
		} catch(Zend_Db_Adapter_Exception $e){
			echo $e->getMessage();
		}
		
		//echo "Database object created. <br />";

		
		// Turn off View Rendering
		$this->_helper->viewRenderer->setNoRender();
	}
	
}